<?php

namespace App\V3\V3_2_7\Services;

use App\Services\CommonService;
use App\V3\V3_2_7\Models\AlbumImgTitleModel;
use Illuminate\Http\JsonResponse;

class AlbumImgTitleService
{
    /**
     *编辑画册图片标题
     * Author: zlf
     * Created at 2024/10/8 15:37
     * @param $data
     * @param $time
     * @return JsonResponse|null
     */
    public static function edit($data, $time): ?JsonResponse
    {
        $bool = false;
        $info = AlbumImgTitleModel::query()->where([
            'album_img' => $data['album_img'],
            'main_id' => $data['main_id'],
            'album_id' => $data['album_id'],
            'flag' => $data['flag'],
            'delete_flag' => 0,
        ])->first();
        if (!empty($info)) {
            $info->img_title = $data['img_title'];
            $bool = $info->save();
        } else {
            $bool = AlbumImgTitleModel::query()->insert($data);
        }
        if ($bool) {
            CommonService::operateResult($data['user_id'], $time, $data, '编辑成功');
            return success();
        } else
            return fail('', '编辑失败');
    }
}
